app.controller('SchoolListController',function ($scope,$controller,SchoolListService,uploadService){
    $controller('baseController',{$scope:$scope});//继承

    $scope.search=function (pageNum,pageSize) {
        SchoolListService.findAll(pageNum,pageSize).success(function (resp) {
            $scope.paginationConf.totalItems=resp.total;
            $scope.list=resp.rows;

        })
    }
    $scope.entity={}
    $scope.gg=function (id) {
        SchoolListService.gg(id).success(function (response) {
            $scope.entity=response;
        })
        if ($scope.entity.status==1){
            $scope.entity.status=2;
           SchoolListService.updatestatus($scope.entity).success(function (response) {
                $scope.reloadList();
            })
        }else {
            $scope.entity.status=1;
            SchoolListService.updatestatus($scope.entity).success(function (response) {
                $scope.reloadList();
            })
        }

    }

    $scope.save=function () {

        var serviceObject;

        if($scope.image_entity.id!=null){
            serviceObject= SchoolListService.update;
        }else{
            serviceObject=SchoolListService.add;
        }

        serviceObject($scope.image_entity).success(function (resp) {
            if(resp.success){
                $scope.reloadList();
            }else {
                alert(resp.message);
            }
        })
    }
    /**
     * 上传图片
     */
    $scope.uploadFile = function () {
        uploadService.uploadFile().success(function (response) {
            if (response.success) {//如果上传成功，取出url
                $scope.image_entity.pic = response.message;//设置文件地址

            } else {
                alert(response.message);
            }
        }).error(function () {
            alert("上传发生错误");
        });
    };


    $scope.entity={goods:{},goodsDesc:{itemImages:[]}};//定义页面实体结构
    //添加图片列表
    $scope.add_image_entity=function(){
        $scope.entity.goodsDesc.itemImages.push($scope.image_entity);
    }
    //列表中移除图片
    $scope.remove_image_entity=function(index){
        $scope.entity.goodsDesc.itemImages.splice(index,1);
    }

    $scope.findOne=function (id) {
        SchoolListService.findOne(id).success(function (resp) {
            $scope.image_entity=resp;
        })
    }

})